package com.order.server.resources;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
//import org.springframework.context.annotation.Configuration;
//import org.springframework.security.authentication.AuthenticationManager;
//import org.springframework.security.config.annotation.web.configuration.EnableWebSecurity;
//import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
//import org.springframework.security.core.userdetails.UserDetailsService;
//import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
//import org.springframework.security.crypto.password.PasswordEncoder;
//import org.springframework.security.oauth2.provider.authentication.OAuth2AuthenticationManager;
//import org.springframework.security.oauth2.provider.token.*;

//@Configuration
//@EnableWebSecurity
public class OAuth2WebSecurityConfig
//        extends WebSecurityConfigurerAdapter
{


//    @Autowired
//    private PasswordEncoder passwordEncoder;
//
//    @Autowired
//    private UserDetailsService userDetailsService;
//
//    @Bean
//    public ResourceServerTokenServices tokenServices(){
//        RemoteTokenServices tokenServices=new RemoteTokenServices();
//        tokenServices.setClientId("orderApp");
//        tokenServices.setClientSecret("123456");
////        tokenServices.setClientSecret(passwordEncoder.encode("123456"));
//        tokenServices.setCheckTokenEndpointUrl("http://localhost:8085/oauth/check_token");//校验token的url
//        // 新增
//        tokenServices.setAccessTokenConverter(getAccessTokenConverter());//作用是把令牌转换成用户信息
//        return tokenServices;
//    }
//
//    private AccessTokenConverter getAccessTokenConverter() {
//        DefaultAccessTokenConverter tokenConverter=new DefaultAccessTokenConverter();
//        DefaultUserAuthenticationConverter authenticationConverter=new DefaultUserAuthenticationConverter();
//        authenticationConverter.setUserDetailsService(userDetailsService);
//        //把用户名转换成一个用户的信息
//        tokenConverter.setUserTokenConverter(authenticationConverter);
//        return tokenConverter;
//
//    }
//
//    @Bean
//    @Override
//    public AuthenticationManager authenticationManagerBean() throws Exception {
//        OAuth2AuthenticationManager auth2AuthenticationManager=new OAuth2AuthenticationManager();
//        auth2AuthenticationManager.setTokenServices(tokenServices());
//        return auth2AuthenticationManager;
//    }
}
